package com.heima;

public class OperatorDemo3 {
    public static void main(String[] args) {
        //自增自减运算符
        int a = 10;

        //a++; //a = a+1;
        ++a;
        System.out.println(a);//a = a+1;

        int b = 10;
        //b--; //b = b-1;
        --b;
        System.out.println(b);

        System.out.println("---------------------------------");
        //表达式中或不是单独使用的情况：++ -- 在前或后面存在区别
        //++ -- 在变量前面：先+1 -1再用
        int i = 10;
        int j = ++i;
        System.out.println(i);//11
        System.out.println(j);//11
        //++ -- 在变量后面：先用再+1 -1
        int m = 10;
        int n = m++;
        System.out.println(m);//11
        System.out.println(n);//10
        System.out.println("----------扩展案例（了解参考）---------------");
        //k 3 4 5 4
        //p 5 4 3 4
        //rs 3+5-4+4-5+4+2=9
        int k = 3;
        int p = 5;
        int rs = k++ + ++k - --p + p-- - k-- + ++p +2;
        System.out.println(k);
        System.out.println(p);
        System.out.println(rs);


    }
}
